package com.adxon.data2;

import java.util.StringTokenizer;

import com.adxon.MsgException;

public class Asset extends Data{
	protected long	ow;
	private Item	owr;

	@Override
	protected void commitExt()throws MsgException{
		super.commitExt();
		commit("ow",ow);
	}
	public void copyOwner(Asset src){
		ow=src.ow;
		tm=0;
	}
	public Item getOwner()throws MsgException{
		if(ow!=0 && owr==null)
			owr=(Item)new Individual().update(ow);
		return owr;
	}
	public long getOwnerId(){
		return ow;
	}
	public boolean isOwnerEquals(Base owner){
		return ow==owner.id;
	}
	public boolean isOwnerEquals(long owner){
		return ow==owner;
	}
	public boolean isOwnerSame(Asset asset){
		return ow==asset.ow;
	}
	public void setAll(Asset src){
		super.setAll(src);
		setOwner(src.ow);
	}
	public void setOwner(Base owner){
		setOwner(owner.id);
	}
	public void setOwner(long owner){
		if(ow!=owner){
			ow=owner;
			tm=0;
		}
	}
	@Override
	public String toString(){
		return id+"."+ow;
	}
	@Override
	public void updateExt()throws MsgException{
		super.updateExt();
		ow=updateLong("ow");
	}
	public Asset update(StringTokenizer ids)throws MsgException{
		update(Long.parseLong(ids.nextToken()));
		if(ow==Long.parseLong(ids.nextToken()))
			return this;
		throw new MsgException(MsgException.NOT_FOUND,null);
	}
}